require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#jobAdmin",
    data:{
        name:"",
        type:"",
        loadFlag:false,
        value:1,
        loginUid:userInfo.id,
        // loginUid:1,
        // list:{
        //     // loginUid:userInfo.id,
        //     loginUid:1,
        //     recruitId:""
        // },
        // isScreen:"",
        getRecruit:{},//上线列表
        getRecruitDown:{},//下线列表
        noticeList2:[],
        enterpriseId:""//企业id
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.enterpriseId=this.searchObject&&this.searchObject.enterpriseId;
        // if(this.type){
        //     if(this.type==5){
        //         this.name="关注";
        //     }else if(this.type==6){
        //         this.name="粉丝";
        //     }
        //     this.myFansList();
        // }
        this.getRecruitByUserId();
        //this.getRecruitDownByUserId();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //tab切换
        getTab:function(num){
            this.value=num;
            if(num==1){
                this.getRecruitByUserId();
            }else if(num==2){
                this.getRecruitDownByUserId();
            }
            //this.myFansList();
        },
        //职位上线列表
        getRecruitByUserId:function(){
            var that=this;
            var data={
                loginUid:that.loginUid
            };
            this.ajax({url:"/happyi/getRecruitByUserId",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.getRecruit=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取列表失败！");
                }
            });
        },
        //职位下线列表
        getRecruitDownByUserId:function(){
            var that=this;
            var data={
                loginUid:that.loginUid
            };
            this.ajax({url:"/happyi/getRecruitDownByUserId",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.getRecruitDown=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取列表失败！");
                }
            });
        },
        //删除职位
        deleteRecruitById:function(recruitId){
            var that=this;
            var data={
                loginUid:that.loginUid,
                recruitId:recruitId
            };
            this.ajax({url:"/happyi/deleteRecruitById",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    that.getRecruitDownByUserId();
                    vm.$refs.prompt.toast("操作成功！");
                }else{
                    vm.$refs.prompt.toast("操作失败！");
                }
            });
        },
        //刷新职位
        updateRecruitById:function(recruitId){
            var that=this;
            var data={
                loginUid:that.loginUid,
                recruitId:recruitId
            };
            this.ajax({url:"/happyi/updateRecruitById",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    that.getRecruitByUserId();
                    vm.$refs.prompt.toast("操作成功！");
                }else{
                    vm.$refs.prompt.toast("操作失败！");
                }
            });
        },
        //职位上线
        upRecruitById:function(recruitId){
            var that=this;
            var data={
                loginUid:that.loginUid,
                recruitId:recruitId
            };
            this.ajax({url:"/happyi/upRecruitById",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    that.getRecruitDownByUserId();
                }else{
                    vm.$refs.prompt.toast("操作失败！");
                }
            });
        },
        //候选人
        getCandidate:function(recruitId,title){
            location.href="/happyi/candidate?type=3&recruitId="+recruitId+"&title="+encodeURI(title);
        },
        getNext:function(type,recruitId){
            var path="/happyi/editJob?type="+type+"&enterpriseId="+this.enterpriseId;
            if(recruitId){
                path+="&recruitId="+recruitId;
            }
            location.href=path;
        }
    }
});